package com.hhhn.wk.widget.dialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hhhn.wk.R;

/**
 * * * * * * * * * * * *
 * @author：WenKe ｡◕‿◕｡ *
 * Data：2017     ｡◕‿◕｡ *
 * QQ：370820580  ｡◕‿◕｡ *
 * Function：     ｡◕‿◕｡ *
 *
 * * * * * * * * * * * */
public class SetPatPwdDialog extends Dialog {
    public SetPatPwdDialog(Context context, int theme) {
        super(context, theme);
    }
    /**
     * Helper class for creating a custom dialog
     */
    public static class Builder {
        private Context context;
        private String okBtn;
        private String cancelBtn;
        private ClickListener positiveListener;
        private View.OnClickListener negativeListener;


        private  View layout;
        public Builder(Context context) {
            this.context = context;

        }

        public interface ClickListener{
            public void click();
        }

        public Builder setOkBtn(String okBtn) {
            this.okBtn = okBtn;
            return this;
        }
        public Builder setCancelBtn(String cancelBtn) {
            this.cancelBtn = cancelBtn;
            return this;
        }

        public Builder setPositiveListener(ClickListener listener) {

            this.positiveListener = listener;
            return this;
        }
        public Builder setNegativeListener(View.OnClickListener listener) {

            this.negativeListener = listener;
            return this;
        }
        /**
         * Create the custom dialog
         */
        public SetPatPwdDialog create() {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // instantiate the dialog with the custom Theme
            final SetPatPwdDialog dialog = new SetPatPwdDialog(context, R.style.paypwdStyle);
            dialog.setCanceledOnTouchOutside(false);
               layout = inflater.inflate(R.layout.set_pay_pwd, null);
            dialog.addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            if (okBtn != null) {
                ((TextView) layout.findViewById(R.id.tv_ok)).setText(okBtn);
            }

            if (cancelBtn != null) {
                ((TextView) layout.findViewById(R.id.tv_cancle)).setText(cancelBtn);
            }


            if(positiveListener != null)
            {
                ((RelativeLayout) layout.findViewById(R.id.rl_ok)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                            positiveListener.click();
                    }
                });
            }
            if(negativeListener != null)
            {
                ((RelativeLayout) layout.findViewById(R.id.rl_cancle)).setOnClickListener(negativeListener);
            }

            dialog.setContentView(layout);

            return dialog;
        }

    }

}
